package cn.rocky.prepare;

public class maximumRows {

    public int maximumRows(int[][] mat, int cols) {
        int m = mat.length, n = mat[0].length;
        int ans = 0;
        for (int i = 1; i < (1 << n); i++) {
            int cnt = 0;
            for (int j = 0; j < n; j++)
                if (((i >> j) & 1) == 1) cnt++;
            if (cnt != cols) continue;
            int sum = 0;
            for (int j = 0; j < m; j++) {
                boolean flag = true;
                for (int k = 0; k < n; k++) {
                    if (mat[j][k] == 1 && ((i >> k) & 1) == 0) {
                        flag = false;
                        break;
                    }
                }
                if (flag) sum++;
            }
            ans = Math.max(ans, sum);
        }
        return ans;
    }
}
